cmake_minimum_required(VERSION 3.14)
if(POLICY CMP0079)
	cmake_policy(SET CMP0079 NEW)
endif()


set(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_LIST_DIR}/)
add_definitions(-DRTC_ENABLE_MEDIA)
set(GETOPT_SOURCES
	getopt.cpp
	getopt.h
)

set(CLIENT_UWP_RESOURCES
	uwp/Logo.png
	uwp/package.appxManifest
	uwp/SmallLogo.png
	uwp/SmallLogo44x44.png
	uwp/SplashScreen.png
	uwp/StoreLogo.png
	uwp/Windows_TemporaryKey.pfx
)
include_directories("C:/thirdpart/include")

include_directories(${CMAKE_CURRENT_LIST_DIR}/async-task)
include_directories(${CMAKE_CURRENT_LIST_DIR}/h265codec)

link_directories("C:/thirdpart/lib")

# 加载dart提供的C语言函数库
include_directories(${CMAKE_CURRENT_LIST_DIR}/include/)

aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/h265codec H265CODEC_SOURCES)
set(MYSRC ${H265CODEC_SOURCES})
message(${MYSRC})
set(CLIENT_SOURCES
	main.cpp
	parse_cl.cpp
	parse_cl.h
	${CMAKE_CURRENT_LIST_DIR}/include/dart_api_dl.c
	${MYSRC}
)
# message(1111 ${MYSRC})
link_libraries(datachannel.lib avcodec.lib avutil.lib swscale.lib SDL2.lib)
if(WIN32)
	if(CMAKE_SYSTEM_NAME STREQUAL "WindowsStore")
		add_executable(datachannel-client ${CLIENT_SOURCES} ${GETOPT_SOURCES} ${CLIENT_UWP_RESOURCES} ${MySRC})
	else()
	    add_executable(datachannel-client ${CLIENT_SOURCES} ${GETOPT_SOURCES} ${MySRC} ${CMAKE_CURRENT_LIST_DIR}/async-task/asynctask.cpp )
	endif()
	target_compile_definitions(datachannel-client PUBLIC STATIC_GETOPT)
else()
	add_executable(datachannel-client ${CLIENT_SOURCES})
endif()

set_target_properties(datachannel-client PROPERTIES
	CXX_STANDARD 17
	OUTPUT_NAME client)

set_target_properties(datachannel-client PROPERTIES
	XCODE_ATTRIBUTE_PRODUCT_BUNDLE_IDENTIFIER com.github.paullouisageneau.libdatachannel.examples.client)

find_package(Threads REQUIRED)


# if(MSVC)
# 	add_custom_command(TARGET datachannel-client POST_BUILD
# 		COMMAND ${CMAKE_COMMAND} -E copy_if_different
# 		"$<TARGET_FILE_DIR:datachannel>/datachannel.dll"
# 		$<TARGET_FILE_DIR:datachannel-client>
# 	)
# endif()
